﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _4_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textMemory_Leave(object sender, EventArgs e)
        {
            private void txtMemory_Leave(object sender, EventArgs e)
        {
            try
            {
                // 尝试将文本框内容转换为int类型
                int memory = int.Parse(txtMemory.Text);
                // 若转换成功，说明输入合法，无需额外操作
            }
            catch
            {
                // 转换失败，提示用户并清空文本框、设置焦点
                MessageBox.Show("内存输入有误，请输入数字！", "输入校验",
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMemory.Text = "";
                txtMemory.Focus();
            }
        }

        private void btnConfirm_Click(object sender, EventArgs e)
        {
            private void btnConfirm_Click(object sender, EventArgs e)
        {
            lstResult.Items.Clear(); // 清空原有内容

            // 1. 添加品牌
            lstResult.Items.Add("品牌：" + cboBrand.Text);

            // 2. 添加CPU
            if (radIntel.Checked) lstResult.Items.Add("CPU：酷睿");
            else if (radAMD.Checked) lstResult.Items.Add("CPU：奔腾");
            else lstResult.Items.Add("CPU：AMD");

            // 3. 添加种类
            if (radLaptop.Checked) lstResult.Items.Add("种类：笔记本");
            else if (radDesktop.Checked) lstResult.Items.Add("种类：台式机");
            else lstResult.Items.Add("种类：平板电脑");

            // 4. 添加外设
            string peripheral = "外设：";
            if (chkHD.Checked) peripheral += "移动硬盘、";
            if (chkDVD.Checked) peripheral += "外置DVD光驱、";
            if (chkMouse.Checked) peripheral += "无线键鼠套装、";
            peripheral = peripheral.TrimEnd('、'); // 去除最后一个顿号
            lstResult.Items.Add(peripheral);

            // 5. 添加内存
            lstResult.Items.Add("内存：" + txtMemory.Text + "G");
        }
    }
    }
    }
}
